import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';

/// @description  自定义的下拉选择样式
///[hintText] 提示字段
///[text] 提示字段
///[width]宽度
///[height]高度
///[padding]内边距
///[onCallBack]点击回调
class CustomDropdownSelection extends StatelessWidget {
  const CustomDropdownSelection({
    super.key,
    this.hintText,
    this.text,
    this.width,
    this.height,
    this.padding,
    this.onCallBack,
  });

  final String? hintText;
  final String? text;
  final double? width;
  final double? height;
  final EdgeInsetsGeometry? padding;
  final Function()? onCallBack;

  String _getText() {
    if (text == '' || text == null) {
      return hintText ?? '请选择';
    } else {
      return text!;
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: width,
      height: height ?? 32.w,
      padding: padding ?? EdgeInsets.symmetric(horizontal: 10.w),
      decoration: BoxDecoration(
          color: Colors.white,
          border: Border.all(color: const Color(0xffF0F0F0), width: 1.w),
          borderRadius: BorderRadius.all(Radius.circular(8.w))),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Expanded(
              child: Text(
            _getText(),
            style: TextStyle(
              overflow: TextOverflow.ellipsis,
              fontSize: 14.sp,
              fontWeight: FontWeight.w400,
              color: (text == null || text == '') ? const Color(0xffA0A7B5) : const Color(0xff495061),
            ),
          )),
          Icon(
            Icons.keyboard_arrow_down_rounded,
            size: 20.w,
            color: const Color(0xff495061),
          )
        ],
      ),
    ).clickOnce(() {
      FocusScope.of(Get.context!).unfocus();
      if (onCallBack != null) {
        onCallBack!();
      }
    });
  }
}
